package com.cbn.lib_screen.utils;

import android.content.Context;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

import com.cbn.lib_screen.DlnaApp;

import java.util.Locale;

/**
 * 描述：
 */
public class VMNetwork {

    /**
     * 获取本地 IP 地址
     */
    public static String getLocalIP() {
        WifiManager wifiManager = (WifiManager) com.cbn.lib_screen.DlnaApp.getContext()
                .getApplicationContext()
                .getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        int ipAddress = wifiInfo.getIpAddress();
        String localIP = String.format(Locale.getDefault(), "%d.%d.%d.%d", (ipAddress & 0xff), (ipAddress >> 8 & 0xff), (ipAddress >> 16 & 0xff), (ipAddress >> 24 & 0xff));
        return localIP;
    }


    /**
     * 获取当前设备 mac 地址
     */
    public static String getMacAddress() {
        WifiManager wifiManager = (WifiManager) com.cbn.lib_screen.DlnaApp.getContext()
                .getApplicationContext()
                .getSystemService(Context.WIFI_SERVICE);
        WifiInfo wifiInfo = wifiManager.getConnectionInfo();
        return wifiInfo.getMacAddress() + "";
    }
}
